#ifndef __FileSize__H__
#define __FileSize__H__

#include <QObject>

QT_BEGIN_NAMESPACE

QT_END_NAMESPACE
class FileSize : public QObject
{
    Q_OBJECT
public:
    explicit FileSize(QObject *parent=nullptr);

    static const qint64 B = 1;
    static const qint64 K = 1024;
    static const qint64 M = 1024 * 1024;
    static const qint64 G = 1024 * 1024 * 1024;
    // static const qint64 T = 1024 * 1024 * 1024 * 1024;

    int m_maxB = 1024;
    int m_maxK = 1024;
    int m_maxM = 1024;
    int m_maxG = 1024;

    void setMaxB(int max) { m_maxB = max; };
    void setMaxK(int max) { m_maxB = max; };
    void setMaxM(int max) { m_maxM = max; };
    void setMaxG(int max) { m_maxG = max; };

    static QString numSizeB(qint64 size) {
        return QString::number(size/B);
    }
    static QString numSizeK(qint64 size) {
        return QString::number(size/K);
    }
    static QString numSizeM(qint64 size) {
        return QString::number(size/M);
    }
    static QString numSizeG(qint64 size) {
        return QString::number(size/G);
    }

    static QString numSize(qint64 size) {
        if (size < K) return QString::number(size / B) + "b";

        if (size < M) return QString::number(size / K) + "Kb";

        if (size < G) return QString::number(size / M) + "Mb";

        /*if (size < T)*/ 
        long T = 1024 * G;
        long E = 1024 * T;
        
        if (size < T) return QString::number(size / G) + "Gb";
        if (size < E) return QString::number(size / T) + "Tb";

        return QString::number(size / E) + "Eb";
    }
};

#endif  //!__FileSize__H__